package entity

import (
	"context"
	"time"

	"github.com/LyricTian/gin-admin/v7/internal/app/schema"
	"github.com/LyricTian/gin-admin/v7/pkg/util/structure"
	"github.com/jinzhu/gorm"
)

// GetGroupVideoDB 获取group_video存储
func GetGroupVideoDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return GetDBWithModel(ctx, defDB, new(GroupVideo))
}

// SchemaGroupVideo group_video对象
type SchemaGroupVideo schema.GroupVideo

// ToGroupVideo 转换为group_video实体
func (a SchemaGroupVideo) ToGroupVideo() *GroupVideo {
	item := new(GroupVideo)
	structure.Copy(a, item)
	return item
}

// GroupVideo group_video实体
type GroupVideo struct {
	ID        string     `gorm:"column:id;primary_key;size:36;"`
	GroupId   string     `gorm:"size:36;column:group_id;"`      // 群ID
	ContentId string     `gorm:"size:36;column:content_id;"`    // 视频ID
	Creator   string     `gorm:"column:creator;size:36;index;"` // 创建者
	CreatedAt time.Time  `gorm:"column:created_at;index;"`
	UpdatedAt time.Time  `gorm:"column:updated_at;index;"`
	DeletedAt *time.Time `gorm:"column:deleted_at;index;"`
}

// ToSchemaGroupVideo 转换为group_video对象
func (a GroupVideo) ToSchemaGroupVideo() *schema.GroupVideo {
	item := new(schema.GroupVideo)
	structure.Copy(a, item)
	return item
}

// GroupVideos group_video列表
type GroupVideos []*GroupVideo

// ToSchemaGroupVideos 转换为group_video对象列表
func (a GroupVideos) ToSchemaGroupVideos() []*schema.GroupVideo {
	list := make([]*schema.GroupVideo, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaGroupVideo()
	}
	return list
}
